<?php

/**
 * browse components.
 *
 * @package    rbis
 * @subpackage browse
 * @author     Norú Moreno, Fahmi Machda
 * @version    SVN: $Id: components.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */

// apps/frontend/modules/browse/actions/components.class.php

class browseComponents extends sfComponents {
  public function executeCategories(sfWebRequest $request) {
    //Model object
    $this->categories = Doctrine::getTable('RbisCategory')->getAllCategories();

    // @todo Generate Report!!!

    echo javascript_tag("
      var selectedItems;
      $(document).ready(function(){
        $('#browser-content input:checkbox').click(function() {
          var generateXML_handler = new XHRHandler();
          //All actions to do after slection of species
          //Obtain selected items into array
          selectedItems = new Array();
          $('#browser-content input:checkbox:checked').each(function() {selectedItems.push($(this).val());});
          $('#report-content').hide();
          $('#statistics-content').html(' ');

          if(selectedItems.length==0){
            map.clearOverlays();
            if (markerClusterer != null)markerClusterer.clearMarkers();
            $('#report-content').html('".__('Please select some items first!')."');
            $('#statistics-content').html(' ');
            $('#xmlfile-content').html(' ');
            $('#gmarkers-content').html(' ');
            return true;
          }
          //Create XML File
          var xmlFile;
          loadAndShow(
            generateXML_handler,
            {
              'speciesList[]': selectedItems
            },
            '".url_for('parser/xml')."',
            'xmlfile-content',
            'xmlfile-loader',
            function(data){

              var generateReport_handler = new XHRHandler();

              //GenerateReport
              loadAndShow(
                generateReport_handler,
                {
                  'speciesList[]': selectedItems
                },
                '".url_for('report/generate')."',
                'report-content',
                'report-loader'
              );

              var generateGMarkers_handler = new XHRHandler();

              //@todo Map LoadAndShow
              loadAndShow(
                generateGMarkers_handler,
                {
                  'speciesList[]': selectedItems
                },
                '".url_for('map/refreshGMarkers')."',
                'gmarkers-content',
                'gmarkers-loader'
              ); //End of GMarkers

              
              if(toggledVertical){
                generateStats();
              }else{
                newPlot=true;
              }
            }
          ); //EndOf XML file creation and nested actions

          //Report generation complete finished

        });//endfunction checkboxes click event
      });//endfunction conbody load
    ");

  }
}